<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料分类">
              <a-input placeholder="请输入物料分类" v-model="queryParam.infoId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('基础物料表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <basepart-modal ref="modalForm" @ok="modalFormOk"></basepart-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BasepartModal from './modules/BasepartModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: "BasepartList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      BasepartModal
    },
    data () {
      return {
        description: '基础物料表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'编码',
            align:"center",
            dataIndex: 'partCode'
          },
          {
            title:'版本号',
            align:"center",
            dataIndex: 'version'
          },
          {
            title:'物料名称',
            align:"center",
            dataIndex: 'partName'
          },
          {
            title:'规格号',
            align:"center",
            dataIndex: 'spec'
          },
          {
            title:'描述',
            align:"center",
            dataIndex: 'desp'
          },
          {
            title:'旧编码',
            align:"center",
            dataIndex: 'oldCode'
          },
          {
            title:'助记码',
            align:"center",
            dataIndex: 'helpcode'
          },
          {
            title:'ABC分类',
            align:"center",
            dataIndex: 'abcCode_dictText'
          },
          {
            title:'图号',
            align:"center",
            dataIndex: 'photoNumber'
          },
          {
            title:'生效日期',
            align:"center",
            dataIndex: 'sdate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'有效开始时间',
            align:"center",
            dataIndex: 'starttime'
          },
          {
            title:'有效结束时间',
            align:"center",
            dataIndex: 'endtime'
          },
          {
            title:'生产类型',
            align:"center",
            dataIndex: 'makeInfo_dictText'
          },
          {
            title:'资源类型',
            align:"center",
            dataIndex: 'zyinfo_dictText'
          },
          {
            title:'是否可销售',
            align:"center",
            dataIndex: 'issell_dictText'
          },
          {
            title:'材质',
            align:"center",
            dataIndex: 'material'
          },
          {
            title:'单重',
            align:"center",
            dataIndex: 'weight'
          },
          {
            title:'毛重',
            align:"center",
            dataIndex: 'mweight'
          },
          {
            title:'系列',
            align:"center",
            dataIndex: 'set1'
          },
          {
            title:'代号',
            align:"center",
            dataIndex: 'dnumber'
          },
          {
            title:'模型',
            align:"center",
            dataIndex: 'model'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'memo'
          },
          {
            title:'是否认证',
            align:"center",
            dataIndex: 'ischecked_dictText'
          },
          {
            title:'是否冻结',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:'基础计量单位',
            align:"center",
            dataIndex: 'baseUnit_dictText'
          },
          {
            title:'销售计量单位',
            align:"center",
            dataIndex: 'saleUnit_dictText'
          },
          {
            title:'采购计量单位',
            align:"center",
            dataIndex: 'purseUnit_dictText'
          },
          {
            title:'生产计量单位',
            align:"center",
            dataIndex: 'prodUnit_dictText'
          },
          {
            title:'库存计量单位',
            align:"center",
            dataIndex: 'stockUnit_dictText'
          },
          {
            title:'发运计量单位',
            align:"center",
            dataIndex: 'fyUnit_dictText'
          },
          {
            title:'数量辅助计量单位',
            align:"center",
            dataIndex: 'suppleUnit'
          },
          {
            title:'数量辅助计量换算率',
            align:"center",
            dataIndex: 'suppleExchange'
          },
          {
            title:'数量精度',
            align:"center",
            dataIndex: 'smaller'
          },
          {
            title:'重量计量单位',
            align:"center",
            dataIndex: 'weightUnit_dictText'
          },
          {
            title:'物料分类',
            align:"center",
            dataIndex: 'infoId'
          },
          {
            title:'销售重量单位',
            align:"center",
            dataIndex: 'sweightunit'
          },
          {
            title:'外购重量单位',
            align:"center",
            dataIndex: 'wunit'
          },
          {
            title:'生产重量单位',
            align:"center",
            dataIndex: 'sunit'
          },
          {
            title:'库存重量单位',
            align:"center",
            dataIndex: 'kunit'
          },
          {
            title:'重量辅助单位',
            align:"center",
            dataIndex: 'fzunit'
          },
          {
            title:'重量换算率',
            align:"center",
            dataIndex: 'fzrate'
          },
          {
            title:'重量精度',
            align:"center",
            dataIndex: 'fzprecision'
          },
          {
            title:'第三计量单位',
            align:"center",
            dataIndex: 'junit'
          },
          {
            title:'销售三量单位',
            align:"center",
            dataIndex: 'saleunit'
          },
          {
            title:'外购三量单位',
            align:"center",
            dataIndex: 'wsunit'
          },
          {
            title:'生产三量单位',
            align:"center",
            dataIndex: 'msunit'
          },
          {
            title:'库存三量单位',
            align:"center",
            dataIndex: 'ksunit'
          },
          {
            title:'发运三量单位',
            align:"center",
            dataIndex: 'fsunit'
          },
          {
            title:'三量辅助单位',
            align:"center",
            dataIndex: 'ssfunit'
          },
          {
            title:'三量换算率',
            align:"center",
            dataIndex: 'srate'
          },
          {
            title:'货币单位',
            align:"center",
            dataIndex: 'currency_dictText'
          },
          {
            title:'销售数量单价',
            align:"center",
            dataIndex: 'price'
          },
          {
            title:'销售重量单价',
            align:"center",
            dataIndex: 'price1'
          },
          {
            title:'销售第三单价',
            align:"center",
            dataIndex: 'price2'
          },
          {
            title:'销售计价方式',
            align:"center",
            dataIndex: 'pstyle_dictText'
          },
          {
            title:'标准交货期',
            align:"center",
            dataIndex: 'paydays'
          },
          {
            title:'标准交货单位',
            align:"center",
            dataIndex: 'payunit'
          },
          {
            title:'外购数量单价',
            align:"center",
            dataIndex: 'wprice'
          },
          {
            title:'外购重量单价',
            align:"center",
            dataIndex: 'wwprice'
          },
          {
            title:'外购第三单价',
            align:"center",
            dataIndex: 'thirdprice'
          },
          {
            title:'外购计价方式',
            align:"center",
            dataIndex: 'wjstyle_dictText'
          },
          {
            title:'标准外购周期',
            align:"center",
            dataIndex: 'wgday'
          },
          {
            title:'标准外购周期单位',
            align:"center",
            dataIndex: 'wgunit'
          },
          {
            title:'生产数量单价',
            align:"center",
            dataIndex: 'madePrice'
          },
          {
            title:'生产重量单价',
            align:"center",
            dataIndex: 'madewprice'
          },
          {
            title:'生产第三单价',
            align:"center",
            dataIndex: 'madethirdprice'
          },
          {
            title:'生产计价方式',
            align:"center",
            dataIndex: 'madestyle_dictText'
          },
          {
            title:'标准生产周期',
            align:"center",
            dataIndex: 'bmakeday'
          },
          {
            title:'标准生产周期单位',
            align:"center",
            dataIndex: 'bmakeunit'
          },
          {
            title:'库存数量单价',
            align:"center",
            dataIndex: 'kprice'
          },
          {
            title:'库存重量单价',
            align:"center",
            dataIndex: 'kwprice'
          },
          {
            title:'库存第三单价',
            align:"center",
            dataIndex: 'kthirdprice'
          },
          {
            title:'库存计价方式',
            align:"center",
            dataIndex: 'kpricestyle_dictText'
          },
          {
            title:'标准存放周期',
            align:"center",
            dataIndex: 'rperiod'
          },
          {
            title:'标准存放有效单位',
            align:"center",
            dataIndex: 'runit'
          },
          {
            title:'最低库存量',
            align:"center",
            dataIndex: 'lowNum'
          },
          {
            title:'最高库存量',
            align:"center",
            dataIndex: 'heightNum'
          },
          {
            title:'安全库存量',
            align:"center",
            dataIndex: 'safeNum'
          },
          {
            title:'批量单位',
            align:"center",
            dataIndex: 'batchUnit'
          },
          {
            title:'最小批量',
            align:"center",
            dataIndex: 'lbatchNum'
          },
          {
            title:'最大批量',
            align:"center",
            dataIndex: 'hbatchnum'
          },
          {
            title:'主工艺路线',
            align:"center",
            dataIndex: 'processroutes'
          },
          {
            title:'批次',
            align:"center",
            dataIndex: 'batch'
          },
          {
            title:'有效批次',
            align:"center",
            dataIndex: 'ybatch'
          },
          {
            title:'标准成品率',
            align:"center",
            dataIndex: 'productrate'
          },
          {
            title:'标准损耗率',
            align:"center",
            dataIndex: 'wastgerate'
          },
          {
            title:'是否关键件',
            align:"center",
            dataIndex: 'ismain_dictText'
          },
          {
            title:'是否专用',
            align:"center",
            dataIndex: 'iszy_dictText'
          },
          {
            title:'检验等级',
            align:"center",
            dataIndex: 'primaryStyle'
          },
          {
            title:'可售期开始',
            align:"center",
            dataIndex: 'salestart',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'可售期结束',
            align:"center",
            dataIndex: 'saleend',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'生产车间',
            align:"center",
            dataIndex: 'depart'
          },
          {
            title:'客户信息',
            align:"center",
            dataIndex: 'customer_dictText'
          },
          {
            title:'产品缩略图  ',
            align:"center",
            dataIndex: 'file',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title:'上传附件',
            align:"center",
            dataIndex: 'uploadfile',
            scopedSlots: {customRender: 'fileSlot'}
          },
          {
            title:'上传附件',
            align:"center",
            dataIndex: 'uploadfile1',
            scopedSlots: {customRender: 'fileSlot'}
          },
          {
            title:'是否工艺目录',
            align:"center",
            dataIndex: 'isbom'
          },
          {
            title:'是否有产品明细',
            align:"center",
            dataIndex: 'iscbom'
          },
          {
            title:'是否冻结',
            align:"center",
            dataIndex: 'status12'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            // fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/basep/basepart/list",
          delete: "/basep/basepart/delete",
          deleteBatch: "/basep/basepart/deleteBatch",
          exportXlsUrl: "/basep/basepart/exportXls",
          importExcelUrl: "basep/basepart/importExcel",
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>